<?php
namespace Home\Controller;
use Think\Controller;




header('Content-Type: text/html; charset=utf-8');

//$weObj->valid();//明文或兼容模式可以在接口验证通过后注释此句，但加密模式一定不能注释，否则会验证失败
$type = $weObj->getRev()->getRevType();
$data = $weObj->getRev()->getRevData();
$kf = $weObj->getCustomServiceKFlist();
foreach($kf as $key=>$value){
	foreach($value as $val){
		$sql = 'select kf_account from custom';
		$resource = mysql_query($sql);
		$list = mysql_fetch_array($resource);
		$res = in_array($list['custom_kf_account'],$val);
		if(!$res){
			$custom_kf_account = $val['kf_account'];
			$sql = "insert into custom VALUES (NULL,$custom_kf_account,$custom_kf_id,$custom_kf_nick,$custom_kf_wx,$custom_kf_headimgurl)";
		}
	}
}
$keyword = $data['Content'];
if($keyword == 1){
//	$weObj->text('您好，我是【客服名】，很高兴为您服务')->reply();
//	$weObj->transfer_customer_service()->reply();
//}
//if($keyword == 2){
//	$weObj->text('请输入MeatFinder肉类定位器账号(e-mail或者是手机号码)')->reply();
	$OpenID = 'oG5yfxOyiMMwZLTDQ-kIAU8J9p4I';
	$txt['touser'] = $OpenID;
	$txt['msgtype'] = 'text';
	$txt['text'] = array('content'=>'New client - no account.');
	$result = $weObj->sendCustomMessage($txt);
}
file_put_contents('text.txt',print_r($val,true));
switch($type) {
	case Wechat::MSGTYPE_TEXT:
//			$weObj->text($type.','.$data['Content'] )->reply();
//			$OpenID = 'oG5yfxOyiMMwZLTDQ-kIAU8J9p4I';
//			$weObj->text('您好，我是【客服名】，很高兴为您服务')->reply();
			break;
	case Wechat::MSGTYPE_EVENT:
			$weObj->text('欢迎回来微粤研发')->reply();
			break;
	case Wechat::MSGTYPE_IMAGE:
			$weObj->text('123')->reply();
			break;
	case Wechat::MSGTYPE_VOICE:
			$weObj->text($type.',789')->reply();
			break;
	case Wechat::MSGTYPE_LOCATION:
			$weObj->text('这么巧,你也在这里啊')->reply();
			break;						
	default:
			$weObj->text("help info")->reply();
}